package com.iwhalecloud.citybrain.flow.platform.manager.infrastructure.web;

import com.iwhalecloud.citybrain.flow.platform.manager.application.service.FlowCatalogueService;
import com.iwhalecloud.citybrain.flow.platform.manager.common.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lilh
 * @date 2020/11/24 下午3:03
 */
@RestController
@RequestMapping("/catalogue")
@Api(value = "获取目录数据", tags = "按层级获取目录数据")
public class FlowCatalogueController {

    @Autowired
    private FlowCatalogueService catalogueService;


    /**
     * 获取整个目录数据
     *
     * @return 目录数据
     */
    @ApiOperation("获取整个目录数据")
    @GetMapping("/listCatalogue")
    public ResponseResult listCatalogue() {
        return ResponseResult.success(catalogueService.listCatalogue());
    }


    /**
     * 获取一级目录（租户）
     *
     * @return 一级目录数据
     */
    @ApiOperation("获取一级目录（租户）")
    @GetMapping("/listRootCatalogue")
    public ResponseResult listRootCatalogue() {
        return ResponseResult.success(catalogueService.listCurrentUserTenants());
    }

    /**
     * 获取二级目录（应用）
     *
     * @param tenantId 租户id
     * @return 应用列表
     */
    @ApiOperation("获取二级目录（应用）")
    @GetMapping("/listAppCatalogue")
    public ResponseResult listAppCatalogue(@RequestParam Integer tenantId) {
        return ResponseResult.success(catalogueService.listCurrentUserApps(tenantId));
    }

    /**
     * 获取三级目录（业务）
     *
     * @param appId 应用id
     * @return 业务列表
     */
    @ApiOperation("获取三级目录（业务）")
    @GetMapping("/listBusiCatalogue")
    public ResponseResult listBusiCatalogue(@RequestParam Integer appId) {
        return ResponseResult.success(catalogueService.listBusiCatalogue(appId));
    }
}
